package com.ihr360.payroll.service.salarytasklet.step.calculator;


import com.ihr360.commons.lang.CollectionUtils;
import com.ihr360.job.core.entity.StepExecutionLog;
import com.ihr360.job.core.logger.CalcLog;

import java.util.ArrayList;
import java.util.List;
/**
 * @author davidwei
 */
public class PersonalCalcLog {

    private List<CalcLog> logs;

    public PersonalCalcLog() {
    }

    public void addLog(CalcLog log) {
        if (logs == null) {
            logs = new ArrayList<>();
        }
        logs.add(log);
    }

    public void addLogs(List<CalcLog> logs) {
        if (logs == null) {
            logs = new ArrayList<>();
        }
        logs.addAll(logs);
    }

    public void addLog(StepExecutionLog.LogLevel level, String title, String content) {
        if (logs == null) {
            logs = new ArrayList<>();
        }
        logs.add(new CalcLog(level, title, content));
    }


    public boolean hasLog() {
        if (CollectionUtils.isNotEmpty(logs)) {
            return true;
        }
        return false;
    }

    public List<CalcLog> getLogs() {
        return logs;
    }

    public void clear() {
        if (this.logs != null) {
            this.logs.clear();
            this.logs = null;
        }
    }

}